package com.mzj.saas.jobs.bill.service;


import cn.hutool.core.util.StrUtil;
import com.mzj.saas.commons.enums.LockAuthTypeEnum;
import com.mzj.saas.commons.enums.RemainingStatusEnum;
import com.mzj.saas.commons.enums.XzLockOperatorTypeEnum;
import com.mzj.saas.commons.util.DateUtils;
import com.mzj.saas.jobs.backlog.entity.SmartLock;
import com.mzj.saas.jobs.backlog.repository.SmartLockRepository;
import com.mzj.saas.jobs.bill.entity.*;
import com.mzj.saas.jobs.bill.repository.*;
import com.mzj.saas.jobs.commons.ResultBean;
import com.mzj.saas.jobs.commons.StatusCode;
import com.mzj.saas.jobs.lock.entity.SmartLockBrand;
import com.mzj.saas.jobs.lock.repository.HouseLockFrozenLogRepository;
import com.mzj.saas.jobs.lock.repository.SmartLockBrandRepository;
import com.mzj.saas.jobs.lock.service.SmartLockBrandService;
import com.mzj.saas.jobs.lock.vo.yaluete.SmartLockVO;
import com.mzj.saas.jobs.lock.vo.yaluete.YltAuthorizationVO;
import com.mzj.saas.jobs.redis.RedisService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * 余额
 */
@Service
public class RemainingService {
    private static Logger log = LoggerFactory.getLogger(RemainingService.class);
    @Autowired
    private GenerateBillService generateBillService;

    @Autowired
    private RedisService redisService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private HouseRemainingRepository houseRemainingRepository;
    @Autowired
    private HouseRemainingRecordRepository houseRemainingRecordRepository;
    @Autowired
    private HouseRemainingRelationRepository houseRemainingRelationRepository;
    @Autowired
    private EstateExpenseBillRepository estateExpenseBillRepository;
    @Autowired
    private EstateRentBillRepository estateRentBillRepository;
    @Autowired
    private HouseRepository houseRepository;
    @Autowired
    private SmartLockAuthRepository smartLockAuthRepository;
    @Autowired
    private SmartLockBleRepository smartLockBleRepository;
    @Autowired
    private SmartLockPwdRepository smartLockPwdRepository;
    @Autowired
    private SmartLockCardRepository smartLockCardRepository;
    @Autowired
    private SmartLockFingerprintRepository smartLockFingerprintRepository;
    @Autowired
    private SmartLockFaceRepository smartLockFaceRepository;
    @Autowired
    private SmartLockRepository smartLockRepository;
    @Autowired
    private LockFrozenRepository lockFrozenRepository;
    @Autowired
    private SmartLockBrandService smartLockBrandService;
    @Autowired
    private SmartLockBrandRepository smartLockBrandRepository;
    @Autowired
    private HouseLockFrozenLogRepository houseLockFrozenLogRepository;
    @Autowired
    private HouseRemainingPostponeRepository houseRemainingPostponeRepository;


    public String work() throws Exception {

        //余额扣减账单并冻结智能锁
        generateBillService.remainingDeductionBill();

        //更新余额账户延期状态
        updateRemainingStatus();


        //更新账户欠费状态
        updateRemainingArrearsStatus();

        //更新账户冻结状态并恢复授权
        updateRemainingThaw();

        return "SUCCESS";
    }


    /**
     * 更新账户冻结状态并恢复授权
     */
    // @Transactional
    public void updateRemainingThaw() {
        try {
            log.info("更新账户冻结状态并恢复授权 end");

            List<HouseRemaining> remainingList = houseRemainingRepository.findByStatus(7);
            for (HouseRemaining houseRemaining : remainingList) {

                Boolean flag = true;

                String houseId = houseRemaining.getHouseId();
                List<HouseRemaining> byHouseId = houseRemainingRepository.findByHouseId(houseId);
                for (HouseRemaining remaining : byHouseId) {
                    if (!remaining.getId().equals(houseRemaining.getId())) {
                        //1正常 2已删除 3延期 4欠费 5已退租 6已退款 7已冻结
                        if (remaining.getStatus() == 7) {
                            flag = false;
                        }
                    }
                }

                //物业其他账单
                List<EstateExpenseBill> expenseBillList = estateExpenseBillRepository.findByAuditStatusAndPaymentStatusAndHouseIdAndOrgId(1, 0, houseId, houseRemaining.getOrgId());
                //物业租金押金
                List<EstateRentBill> rentBillList = estateRentBillRepository.findByAuditStatusAndPaymentStatusAndHouseIdAndOrgId(1, 0, houseId, houseRemaining.getOrgId());

                if (expenseBillList.size() + rentBillList.size() == 0) {
                    houseRemaining.setStatus(RemainingStatusEnum.NORMAL.getValue());
                    if (flag) {
                        //判断是否合租
                        List<SmartLockAuth> smartLockAuths = new ArrayList<>();
                        Optional<House> byId = houseRepository.findById(houseId);
                        if (byId.isPresent()) {
                            House house = byId.get();
                            if (house.getHousemateId() != null) {
                                smartLockAuths = smartLockAuthRepository.findBySubHouseId(houseId);

                            } else {
                                smartLockAuths = smartLockAuthRepository.findByHouseId(houseId);
                            }
                        }
                        //智能锁授权解冻
                        smartLockThaw(smartLockAuths);

                    }
                }


            }
            houseRemainingRepository.saveAll(remainingList);
            log.info("更新账户冻结状态并恢复授权 end");
        } catch (Exception e) {
            log.error("更新账户欠费状态 " + e.getMessage(), e);

        }
    }

    /**
     * 智能锁授权解冻
     *
     * @param smartLockAuths
     */
    // @Transactional
    public void smartLockThaw(List<SmartLockAuth> smartLockAuths) {
        try {
            String reason = "账户已缴清，系统解冻";
            log.info("更新账户冻结状态并恢复授权 start");
            String systemUser = redisService.getSystemUser();
            Date date = new Date();
            if (!smartLockAuths.isEmpty()) {
                for (SmartLockAuth smartLockAuth : smartLockAuths) {
                    Long lockAuthId = smartLockAuth.getId();

                    Optional<SmartLock> lockOptional = smartLockRepository.findById(smartLockAuth.getLockId());
                    if (!lockOptional.isPresent()) {
                        break;
                    }
                    SmartLock smartLock = lockOptional.get();
                    // 单用户授权冻结, 一次冻结密码、身份证、CPU、指纹
                    SmartLockPwd pwd = smartLockPwdRepository.findByLockAuthId(lockAuthId);
                    List<SmartLockCard> cards = smartLockCardRepository.findByLockAuthId(lockAuthId);
                    List<SmartLockFingerprint> fingerprint = smartLockFingerprintRepository.findByLockAuthId(lockAuthId);
                    SmartLockBle ble = smartLockBleRepository.findByLockAuthId(lockAuthId);
                    SmartLockFace face = smartLockFaceRepository.findByLockAuthId(lockAuthId);
                    if (pwd != null || !cards.isEmpty() || !fingerprint.isEmpty() || ble != null || face != null) {
                        // 新增冻结记录
                        String houseId = smartLock.getHouseId();
                        //String matchUserName = smartLock.getMatchUserName();
                        String communityName = smartLock.getCommunityName();
                        String buildName = smartLock.getBuildName();
                        String unitName = smartLock.getUnitName();
                        String roomNumber = smartLock.getRoomNumber();

                        LockFrozen lockFrozen = new LockFrozen();
                        lockFrozen.setType(0);
                        lockFrozen.setLockId(smartLockAuth.getLockId());
                        lockFrozen.setLockAuditId(lockAuthId);
                        lockFrozen.setHouseId(houseId);
                        lockFrozen.setMatchUserName(smartLockAuth.getUserName());
                        lockFrozen.setCommunityName(communityName);
                        lockFrozen.setBuildName(buildName);
                        lockFrozen.setUnitName(unitName);
                        lockFrozen.setRoomNumber(roomNumber);
                        lockFrozen.setOperationState(2);
                        lockFrozen.setOperationTime(date);
                        if (StringUtils.isNotBlank(reason)) {
                            lockFrozen.setReason(reason);
                        }
                        LockFrozen frozenSave = lockFrozenRepository.save(lockFrozen);

                        // 冻结密码
                        if (pwd != null) {
                            SmartLockVO smartLockVO = new SmartLockVO();
                            smartLockVO.setSn(smartLock.getSn());
                            smartLockVO.setIndex(pwd.getPwdIndex());
                            smartLockVO.setAuthInfoId(lockAuthId);
                            Integer authType = pwd.getAuthType();
                            if (authType == 1 || authType == 2) {
                                smartLockVO.setAuthType(LockAuthTypeEnum.NORMAL_PASS.getValue());
                            } else if (authType == 3) {
                                smartLockVO.setAuthType(LockAuthTypeEnum.TIMES_PASS.getValue());
                                smartLockVO.setTimes(pwd.getTimes());
                            }
                            smartLockVO.setSuspend(0);// 0:解冻 1:冻结
                            smartLockVO.setLockFrozenId(frozenSave.getId());
                            smartLockVO.setIndexNum(pwd.getPwdIndexNum());
                            //亚略特
                            if (smartLock.getBrandId() == 3L) {
                                YltAuthorizationVO yltVO = new YltAuthorizationVO();
                                yltVO.setfLockMAC(smartLock.getMac());
                                yltVO.setfAppUserID(pwd.getfAppUserId());
                                yltVO.setfBeginDate(DateUtils.format(pwd.getStartTime(), DateUtils.FORMAT_DATETIME_14));
                                yltVO.setfEndDate(DateUtils.format(pwd.getEndTime(), DateUtils.FORMAT_DATETIME_14));
                                yltVO.setfOpenByPassword(1);
                                yltVO.setfOpenByIDCard(0);
                                yltVO.setfOpenByBLE(0);
                                yltVO.setfOpenByFinger(0);
                                yltVO.setfOpenByICCard(0);
                                yltVO.setfOpenPassword(pwd.getPassword());
                                smartLockVO.setYltAuth(yltVO);
                            }

                            ResultBean<String> stringResultBean = smartLockBrandService.freezeOrUnfreeze(smartLockVO,
                                    smartLock.getBrandId(), XzLockOperatorTypeEnum.PWD.getValue());
                            String msg = stringResultBean.getMsg();
                            String code = stringResultBean.getCode();
                            if (!code.equals(StatusCode.SUCCESS_CODE_10000.getErrorCode())) {
                                log.error("LockAppService frozenOrUnfrozenAuth---> " + msg);
                                // 失败，删除冻结记录
                                lockFrozenRepository.deleteById(frozenSave.getId());
                            } else {
                                // 冻结后默认待执行
                                pwd.setStatus(0);
                                smartLockPwdRepository.save(pwd);
                                //亚略特
                                //if (smartLock.getBrandId() == 3L) {
                                generateBillService.yltUpdateStatus(pwd, null, null, null, null, 0, stringResultBean, smartLockAuth, lockFrozen,smartLock);
                                //}
                            }
                        }

                        // 冻结卡
                        if (!cards.isEmpty()) {
                            for (SmartLockCard card : cards) {
                                SmartLockVO smartLockVO = new SmartLockVO();
                                smartLockVO.setSn(smartLock.getSn());
                                smartLockVO.setIndex(card.getCardIndex());
                                smartLockVO.setAuthInfoId(lockAuthId);
                                smartLockVO.setCardType(card.getType());
                                smartLockVO.setSuspend(0);// 0:解冻 1:冻结
                                smartLockVO.setLockFrozenId(frozenSave.getId());
                                smartLockVO.setIndexNum(card.getCardIndexNum());
                                //亚略特
                                if (smartLock.getBrandId() == 3L) {
                                    YltAuthorizationVO yltVO = new YltAuthorizationVO();
                                    yltVO.setfLockMAC(smartLock.getMac());
                                    yltVO.setfAppUserID(card.getfAppUserId());
                                    yltVO.setfBeginDate(DateUtils.format(card.getStartTime(), DateUtils.FORMAT_DATETIME_14));
                                    yltVO.setfEndDate(DateUtils.format(card.getEndTime(), DateUtils.FORMAT_DATETIME_14));
                                    yltVO.setfOpenByPassword(0);
                                    yltVO.setfOpenByBLE(0);
                                    yltVO.setfOpenByFinger(0);
                                    if (card.getType() == 1) {
                                        yltVO.setfOpenByIDCard(1);
                                        yltVO.setfOpenByICCard(0);
                                    } else {
                                        yltVO.setfOpenByIDCard(0);
                                        yltVO.setfOpenByICCard(1);
                                    }
                                    yltVO.setfIDCardID(card.getCardId());
                                    yltVO.setfIDCardNumber(card.getCardNumber());
                                    smartLockVO.setYltAuth(yltVO);
                                }

                                ResultBean<String> stringResultBean = smartLockBrandService.freezeOrUnfreezeCard(smartLockVO,
                                        smartLock.getBrandId(), XzLockOperatorTypeEnum.CARD.getValue());
                                String msg = stringResultBean.getMsg();
                                String code = stringResultBean.getCode();
                                if (!code.equals(StatusCode.SUCCESS_CODE_10000.getErrorCode())) {
                                    log.error("LockAppService frozenOrUnfrozenAuth---> " + msg);
                                    // 失败，删除冻结记录
                                    lockFrozenRepository.deleteById(frozenSave.getId());
                                } else {
                                    // 冻结后默认待执行
                                    card.setStatus(0);
                                    smartLockCardRepository.save(card);
                                    //亚略特
                                    //if (smartLock.getBrandId() == 3L) {
                                    generateBillService.yltUpdateStatus(null, card, null, null, null, 0, stringResultBean, smartLockAuth, lockFrozen,smartLock);
                                    //}
                                }
                            }
                        }

                        // 指纹锁
                        if (!fingerprint.isEmpty()) {
                            Optional<SmartLockBrand> optional = smartLockBrandRepository.findById(smartLock.getBrandId());
                            if (optional.isPresent()) {
                                SmartLockBrand brand = optional.get();
                                // 品牌支持指纹锁
                                if (brand.getFingerprintStatus() != null && brand.getFingerprintStatus() == 1) {
                                    for (SmartLockFingerprint fg : fingerprint) {
                                        SmartLockVO smartLockVO = new SmartLockVO();
                                        smartLockVO.setSn(smartLock.getSn());
                                        smartLockVO.setIndex(fg.getFingerprintIndex());
                                        smartLockVO.setIndexNum(fg.getFingerprintIndexNum());
                                        smartLockVO.setAuthInfoId(lockAuthId);
                                        smartLockVO.setSuspend(0);// 0:解冻 1:冻结
                                        smartLockVO.setLockFrozenId(frozenSave.getId());
                                        smartLockVO.setIndexNum(fg.getFingerprintIndexNum());
                                        //亚略特
                                        if (smartLock.getBrandId() == 3L) {

                                            YltAuthorizationVO yltVO = new YltAuthorizationVO();
                                            yltVO.setfLockMAC(smartLock.getMac());
                                            yltVO.setfAppUserID(fg.getfAppUserId());
                                            yltVO.setfBeginDate(DateUtils.format(fg.getStartTime(), DateUtils.FORMAT_DATETIME_14));
                                            yltVO.setfEndDate(DateUtils.format(fg.getEndTime(), DateUtils.FORMAT_DATETIME_14));
                                            yltVO.setfOpenByPassword(0);
                                            yltVO.setfOpenByIDCard(0);
                                            yltVO.setfOpenByBLE(0);
                                            yltVO.setfOpenByFinger(1);
                                            yltVO.setfOpenByICCard(0);
                                            yltVO.setfFingerFeature(fg.getFingerprint());
                                            smartLockVO.setYltAuth(yltVO);

                                        }

                                        ResultBean<String> stringResultBean = smartLockBrandService.freezeOrUnfreezeFingerprint(
                                                smartLockVO, smartLock.getBrandId(), XzLockOperatorTypeEnum.FINGERPRINT.getValue());
                                        String msg = stringResultBean.getMsg();
                                        String code = stringResultBean.getCode();
                                        if (code != StatusCode.SUCCESS_CODE_10000.getErrorCode()) {
                                            log.error("LockAppService deleteUser---> " + msg);
                                            // 失败，删除冻结记录
                                            lockFrozenRepository.deleteById(frozenSave.getId());
                                        } else {
                                            // 冻结后默认待执行
                                            fg.setStatus(0);
                                            smartLockFingerprintRepository.save(fg);
                                            //亚略特
                                            //if (smartLock.getBrandId() == 3L) {
                                            generateBillService.yltUpdateStatus(null, null, fg, null, null, 0, stringResultBean, smartLockAuth, lockFrozen,smartLock);
                                            //}
                                        }
                                    }
                                }
                            }
                        }

                        //蓝牙
                        if (ble != null) {
                            SmartLockVO smartLockVO = new SmartLockVO();
                            smartLockVO.setSn(smartLock.getSn());
                            smartLockVO.setAuthInfoId(lockAuthId);
                            smartLockVO.setSuspend(0);// 0:解冻 1:冻结
                            smartLockVO.setLockFrozenId(frozenSave.getId());
                            //亚略特
                            if (smartLock.getBrandId() == 3L) {
                                YltAuthorizationVO yltVO = new YltAuthorizationVO();
                                yltVO.setfLockMAC(smartLock.getMac());
                                yltVO.setfAppUserID(ble.getfAppUserId());
                                yltVO.setfBeginDate(DateUtils.format(ble.getStartTime(), DateUtils.FORMAT_DATETIME_14));
                                yltVO.setfEndDate(DateUtils.format(ble.getEndTime(), DateUtils.FORMAT_DATETIME_14));
                                yltVO.setfOpenByPassword(0);
                                yltVO.setfOpenByIDCard(0);
                                yltVO.setfOpenByBLE(1);
                                yltVO.setfOpenByFinger(0);
                                yltVO.setfOpenByICCard(0);
                                smartLockVO.setYltAuth(yltVO);
                            }

                            ResultBean<String> stringResultBean = smartLockBrandService.freezeOrUnfreezeBle(smartLockVO, smartLock.getBrandId());
                            String msg = stringResultBean.getMsg();
                            String code = stringResultBean.getCode();
                            if (!code.equals(StatusCode.SUCCESS_CODE_10000.getErrorCode())) {
                                log.error("LockAppService frozenOrUnfrozenAuth---> " + msg);
                                // 失败，删除冻结记录
                                lockFrozenRepository.deleteById(frozenSave.getId());
                            } else {
                                // 冻结后默认待执行
                                ble.setStatus(0);
                                smartLockBleRepository.save(ble);
                                //亚略特
                                //if (smartLock.getBrandId() == 3L) {
                                generateBillService.yltUpdateStatus(null, null, null, ble, null, 0, stringResultBean, smartLockAuth, lockFrozen,smartLock);
                                //}
                            }
                        }

                        // 人脸
                        if (face != null) {
                            SmartLockVO smartLockVO = new SmartLockVO();
                            smartLockVO.setSn(smartLock.getSn());
                            smartLockVO.setAuthInfoId(lockAuthId);
                            smartLockVO.setSuspend(0);// 0:解冻 1:冻结
                            smartLockVO.setLockFrozenId(frozenSave.getId());

                            face.setSn(smartLock.getSn());
                            ResultBean<String> stringResultBean = smartLockBrandService.freezeOrUnfreezeFace(smartLockVO, face, smartLock.getBrandId());
                            String resultData = stringResultBean.getResultData();
                            String msg = stringResultBean.getMsg();
                            String code = stringResultBean.getCode();
                            if (!code.equals(com.mzj.saas.commons.StatusCode.SUCCESS_CODE_10000.getErrorCode())) {
                                log.error("LockAppService frozenOrUnfrozenAuth---> " + msg);
                                // 失败，删除冻结记录
                                lockFrozenRepository.deleteById(frozenSave.getId());
                            } else {
                                face.setReturnFaceId(StrUtil.isEmpty(resultData) ? null : Long.valueOf(resultData));
                                face.setIdentification(resultData);
                                // 冻结后默认待执行
                                face.setStatus(0);
                                smartLockFaceRepository.save(face);
                                // 亚略特
                                // if (smartLock.getBrandId() == 3L) {
                                generateBillService.yltUpdateStatus(null, null, null, null, face, 0, stringResultBean, smartLockAuth, lockFrozen,smartLock);
                                //}
                            }
                        }

                    }

                    //  写入冻结日志表
                    HouseLockFrozenLog houseLockFrozenLog = new HouseLockFrozenLog();
                    houseLockFrozenLog.setType(0);// 操作类型: 0:解冻 1:冻结
                    houseLockFrozenLog.setLockId(smartLock.getId());// 智能锁绑定id
                    houseLockFrozenLog.setHouseId(smartLock.getHouseId()); // 公租房id
                    houseLockFrozenLog.setLockAuditId(lockAuthId); // 授权信息id
                    houseLockFrozenLog.setOperationTime(new Date()); // 操作时间
                    houseLockFrozenLog.setOperationState(2);
                    houseLockFrozenLogRepository.save(houseLockFrozenLog);

                    /**
                     * 产生智能锁冻结/解冻待办事项
                     */
                    generateBillService.addBacklogItem(smartLockAuth.getMobile(), reason, 0, smartLock.getHouseId(), smartLockAuth.getAuthorUserId(), systemUser);
                    //更新亚略特智能锁状态
                    generateBillService.yltUpdateLockStatus(smartLock, 0);
                    //更新锁授权人数
                    generateBillService.updateOauthNumber(smartLock.getBrandId(), smartLockAuth.getLockId());
                }

            }
            log.info("更新账户冻结状态并恢复授权 end");
        } catch (Exception e) {
            log.error("智能锁授权解冻失败 " + e.getMessage(), e);
        }


    }

    private void updateRemainingArrearsStatus() {
        try {
            log.info("更新账户欠费状态 end");
            List<HouseRemaining> remainingList = houseRemainingRepository.findByStatus(RemainingStatusEnum.DEFAULTING.getValue());
            for (HouseRemaining remaining : remainingList) {
                String houseId = remaining.getHouseId();
                //物业其他账单
                List<EstateExpenseBill> expenseBillList = estateExpenseBillRepository.findByAuditStatusAndPaymentStatusAndHouseId(1, 0, houseId);
                //物业租金押金
                List<EstateRentBill> rentBillList = estateRentBillRepository.findByAuditStatusAndPaymentStatusAndHouseId(1, 0, houseId);
                if ((expenseBillList.size() + rentBillList.size()) == 0) {
                    remaining.setStatus(RemainingStatusEnum.NORMAL.getValue());
                    houseRemainingRepository.save(remaining);
                }
            }
            log.info("更新账户欠费状态 end");
        } catch (Exception e) {
            log.error("更新账户欠费状态 " + e.getMessage(), e);
        }
    }

    //更新余额账户延期状态
    private void updateRemainingStatus() {
        Date date = new Date();
        long time = date.getTime();
        try {

            log.info("更新余额账户延期状态 start");
            List<HouseRemaining> remainingList = houseRemainingRepository.findByStatus(RemainingStatusEnum.POSTPONE.getValue());
            for (HouseRemaining remaining : remainingList) {
                if (remaining.getDeferredEndTime().getTime() < time) {
                    //延期状态 0延期 1取消延期
                    List<HouseRemainingPostpone> postpones = houseRemainingPostponeRepository.findByRemainingIdAndPostponeTypeOrderByLastUpdateTimeDesc(remaining.getId(), 0);
                    if (postpones.isEmpty()) {
                        log.error(remaining.getId() + "不存在！");
                        continue;
                    }
                    HouseRemainingPostpone postpone = postpones.get(0);
                    postpone.setCancelStatus(1);

                    Integer status = remaining.getStatus();
                    if (status != null && status.equals(RemainingStatusEnum.POSTPONE.getValue())) {
                        remaining.setStatus(RemainingStatusEnum.NORMAL.getValue());
                        remaining.setDeferredEndTime(new Date());

                        HouseRemainingPostpone returnPost = new HouseRemainingPostpone();
                        returnPost.setRemainingId(remaining.getId());
                        returnPost.setPostponeType(1);
                        returnPost.setOperatorId(redisService.getSystemUser());
                        returnPost.setLastUpdateTime(date);
                        returnPost.setCause("延期时间已到期，系统取消延期");
                        returnPost.setDeferredStartTime(remaining.getDeferredStartTime());
                        returnPost.setDeferredEndTime(date);
                        returnPost.setPostponeId(postpone.getId());

                        houseRemainingRepository.save(remaining);
                        houseRemainingPostponeRepository.save(postpone);
                        houseRemainingPostponeRepository.save(returnPost);
                    }
                }
            }
            log.info("更新余额账户延期状态 end");
        } catch (Exception e) {
            log.error("更新余额账户延期状态 " + e.getMessage(), e);
        }
    }

}
